﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DefCore.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DefCore.Tools;

namespace DefCore
{
    public enum CellConverterEnum {
        Open = 1,
        Closed = 2,
        Stone = 3,
        Water = 4,
        Lava = 5,
        IronOre = 6,
        Coal = 7,
    }


    public sealed class TileBin
    { 
        //Singleton Pattern
        private static TileBin _Instance;
        public static TileBin Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new TileBin();

                return _Instance;
            }
        }
        
        //Fields
        private Dictionary<int, Texture2D> _TileBank;
        
        //ctor
        protected TileBin()
        {
            _TileBank = new Dictionary<int, Texture2D>();
        }

        //Methods
        public void Load()
        {
            _TileBank.Add((int)CellConverterEnum.Open, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(000, 000, 256, 256)));
            _TileBank.Add((int)CellConverterEnum.Closed, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(256, 000, 256, 256)));
            _TileBank.Add((int)CellConverterEnum.Stone, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(512, 000, 256, 256)));            
            _TileBank.Add((int)CellConverterEnum.Water, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(000, 512, 256, 256)));
            _TileBank.Add((int)CellConverterEnum.Lava, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(256, 512, 256, 256)));

            _TileBank.Add((int)CellConverterEnum.Coal, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(256, 000, 256, 256)));
            _TileBank.Add((int)CellConverterEnum.IronOre, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(256, 000, 256, 256)));

            SpriteSheetHelper.OverrideBackgroundColor = new Color(0xff, 0xff, 0xff, 0x00);
            _TileBank.Add(100, SpriteSheetHelper.Retreive(ResourceBin.Instance.Get<Texture2D>("ASSET_TEXTUREPAK"), new Rectangle(512, 512, 256, 256), true));
        }
        public Texture2D GetTile(int index)
        {
            return _TileBank[index];
        }

    }
    
}
